package com.walle.ak47.commons.jaxrs.cxf.header;

import java.util.Date;

import com.walle.ak47.commons.utils.AESCodec;
import com.walle.ak47.commons.utils.ConvertUtils;

public class HeaderInfo {

	private String token;
	private int appId;
	private long time;
	private boolean isEffective;
	
	public HeaderInfo() {
	}

	public HeaderInfo(String token, int appId, long time) {
		this.token = token;
		this.appId = appId;
		this.time = time;
		this.isEffective = true;
	}
	
	public boolean checkAndGet(String xAuthHeader) throws Exception {
		
		int appId = ConvertUtils.toInt(AESCodec.decode(xAuthHeader));
		
		this.isEffective = appId < 0 ? false : true;
		if (isEffective) {
			this.token = xAuthHeader;
			this.appId = appId;
			this.time = new Date().getTime();
		}

		return true;
	}

	public String getToken() {
		return token;
	}

	public int getAppId() {
		return appId;
	}

	public long getTime() {
		return time;
	}

	public boolean isEffective() {
		return isEffective;
	}
}
